package com.zat.mes.andrmes.dofun.work.vm

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.love.zywanandroid.retrofit.RetrofitManager
import com.love.zywanandroid.retrofit.api.ApiService
import com.tencent.bugly.proguard.s
import com.zat.mes.andrmes.data.*
import com.zat.mes.andrmes.retrofit.callback.MesCallBack
import okhttp3.RequestBody
import retrofit2.Call
import retrofit2.Response

/**
 * @author zy
 * @date :2020-09-12 13:59
 * @description: 领纱 model
 */
class YarnInModel:ViewModel() {

    private val yarnInData: MutableLiveData<String> = MutableLiveData()
    private val yarnUnData: MutableLiveData<String> = MutableLiveData()

    private val scheduList:MutableLiveData<BaseResponse<SelectScheduBean>> = MutableLiveData()
    private val badFlatList:MutableLiveData<BaseResponse<BadFlatBean>> = MutableLiveData()
    private val yarnInList:MutableLiveData<BaseResponse<YarnInBean>> = MutableLiveData()
    private val yarnUnList:MutableLiveData<BaseResponse<YarnUnBean>> = MutableLiveData()

    fun getScheduList(): LiveData<BaseResponse<SelectScheduBean>> {
        return scheduList
    }
    fun getBadFlatList(): LiveData<BaseResponse<BadFlatBean>> {
        return badFlatList
    }

    fun getYarnInData(): LiveData<String> {
        return yarnInData
    }
    fun getYarnUnData(): LiveData<String> {
        return yarnUnData
    }
    fun getYarnInList():LiveData<BaseResponse<YarnInBean>>{
        return yarnInList
    }
    fun getYarnUnList():LiveData<BaseResponse<YarnUnBean>>{
        return yarnUnList
    }
    /**
     * 获取排班表
     */
    fun getScheduList(currentPage:Int,pageSize:Int,workShopId:String?){

        RetrofitManager.apiService(ApiService::class.java)
            .getScheduList(currentPage,pageSize,workShopId)
            .enqueue(object :MesCallBack<BaseResponse<SelectScheduBean>>(){
                override fun onSuccessful(
                    call: Call<BaseResponse<SelectScheduBean>>?,
                    response: Response<BaseResponse<SelectScheduBean>>?
                ) {
                    scheduList.postValue(response?.body())
                }

            })
    }
    /**
     * 获取排班表
     */
    fun getBadFlatList(currentPage:Int,pageSize:Int,workShopId:String?){

        RetrofitManager.apiService(ApiService::class.java)
            .getBadFlatList(currentPage,pageSize,0)
            .enqueue(object :MesCallBack<BaseResponse<BadFlatBean>>(){
                override fun onSuccessful(
                    call: Call<BaseResponse<BadFlatBean>>?,
                    response: Response<BaseResponse<BadFlatBean>>?
                ) {
                    badFlatList.postValue(response?.body())
                }

            })
    }

    /**
     * 领纱
     */
    fun postYarnIn(json:String){
        val requestBody: RequestBody = RequestBody.create(RetrofitManager.JOSNTYPE, json)
        RetrofitManager.apiService(ApiService::class.java)
            .postYarnIn(requestBody)
            .enqueue(object :MesCallBack<BaseResponse<String>>(){
                override fun onSuccessful(
                    call: Call<BaseResponse<String>>?,
                    response: Response<BaseResponse<String>>?
                ) {
                    yarnInData.postValue(response?.body()?.message)
                }

            })
    }

    /**
     * 领纱
     */
    fun postYarnUn(json:String){
        val requestBody: RequestBody = RequestBody.create(RetrofitManager.JOSNTYPE, json)
        RetrofitManager.apiService(ApiService::class.java)
            .postYarnUn(requestBody)
            .enqueue(object :MesCallBack<BaseResponse<String>>(){
                override fun onSuccessful(
                    call: Call<BaseResponse<String>>?,
                    response: Response<BaseResponse<String>>?
                ) {
                    yarnUnData.postValue(response?.body()?.message)
                }

            })
    }

    /**
     * 获取领纱列表
     */
    fun getYarnInList(currentPage:Int,pageSize:Int,workShopId:String?){

        RetrofitManager.apiService(ApiService::class.java)
            .getYarnInList(currentPage,pageSize,workShopId)
            .enqueue(object :MesCallBack<BaseResponse<YarnInBean>>(){
                override fun onSuccessful(
                    call: Call<BaseResponse<YarnInBean>>?,
                    response: Response<BaseResponse<YarnInBean>>?
                ) {
                    yarnInList.postValue(response?.body())
                }

            })
    }

    /**
     * 获取退纱列表
     */
    fun getYarnUnList(currentPage:Int,pageSize:Int,workShopId:String?){

        RetrofitManager.apiService(ApiService::class.java)
            .getYarnUnList(currentPage,pageSize,workShopId)
            .enqueue(object :MesCallBack<BaseResponse<YarnUnBean>>(){
                override fun onSuccessful(
                    call: Call<BaseResponse<YarnUnBean>>?,
                    response: Response<BaseResponse<YarnUnBean>>?
                ) {
                    yarnUnList.postValue(response?.body())
                }

            })
    }
}